﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoodsInvoicing.Presentions.Presenter;
using GoodsInvoicing.Views.View;
using GoodsInvoicing.BLL.Service;
using GoodsInvoicing.Model.Menu;
using System.Windows.Forms;
using GoodsInvoicing.Views.ViewImpl;

namespace GoodsInvoicing.Presentions.PresenterImpl
{
    public class MainFormPresenter : IMainFormPresenter
    {
        #region 构造
        /// <summary>
        /// 无接口的构造被阻止
        /// </summary>
        private MainFormPresenter()
        {
            throw new NotSupportedException("无接口的实现.");
        }
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="view">视图接口</param>
        public MainFormPresenter(IMainForm view, IGI_MenuService menuService)
        {
            this.view = view;
            this.menuService = menuService;
        }
        #endregion

        #region 属性
        private IMainForm view;
        /// <summary>
        /// 视图接口
        /// </summary>
        public IMainForm View
        {
            get { return view; }
        }

        private IGI_MenuService menuService;
        public IGI_MenuService MenuService
        {
            get { return menuService; }
        }
        #endregion

        #region 方法
        public void InitializeView()
        {
            this.View.MainMenuLoad += new EventHandler<EventArgs>(View_MainMenuLoad);
            this.View.SubMenuClick += new EventHandler(View_SubMenuClick);
        }

        #endregion

        /// <summary>
        /// 菜单读取事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void View_MainMenuLoad(object sender, EventArgs e) 
        { 
            if(this.View.User.LoginName != "")
            {
                string loginName = this.View.User.LoginName;
                IDictionary<GI_Menu, IList<GI_Menu>> menus = menuService.GetMenus(loginName);
                this.View.ShowMenu(menus);
            }

        }

        /// <summary>
        /// 点击二级菜单事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void View_SubMenuClick(object sender, EventArgs e) 
        {
            if (this.View.User.LoginName != "")
            {
                switch ((sender as ToolStripMenuItem).Text)
                {
                    case "商品基本信息管理":
                        MessageBox.Show("商品基本信息管理弹出框");
                        break;
                    case "商品入库管理":
                        MessageBox.Show("商品入库管理弹出框");
                        break;
                    case "商品出库管理":
                        MessageBox.Show("商品出库管理弹出框");
                        break;
                    case "商品盘库管理":
                        MessageBox.Show("商品盘库管理弹出框");
                        break;
                    case "交班管理":
                        MessageBox.Show("交班管理弹出框");
                        break;
                    case "库存统计":
                        MessageBox.Show("库存统计弹出框");
                        break;
                    case "交班统计":
                        MessageBox.Show("交班统计弹出框");
                        break;
                    case "用户管理":
                        UserListForm ulForm = UserListForm.getInstance();
                        ulForm.MdiParent = this.View.Form;
                        //ulForm.WindowState = FormWindowState.Maximized;
                        ulForm.StartPosition = FormStartPosition.CenterScreen;
                        ulForm.Show();                        
                        break;
                    case "权限管理":
                        MessageBox.Show("权限管理弹出框");
                        break;
                    case "登录登出管理":
                        MessageBox.Show("登录登出管理弹出框");
                        break;
                    case "帮助文档":
                        MessageBox.Show("帮助文档弹出框");
                        break;
                    case "关于":
                        MessageBox.Show("关于弹出框");
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
